"""策略使用的数据规范"""

from entity import Entity


class TickEntity(Entity):
    """策略用Tick数据"""
    symbol: str
    datetime: str
    tradingday: str = ''
    updatetime: str = ''
    updatemillisec: int = 0

    volume: int = 0
    open_interest: int = 0
    last_price: float = 0
    last_volume: int = 0
    limit_up: float = 0
    limit_down: float = 0

    open_price: float = 0
    high_price: float = 0
    low_price: float = 0
    pre_close: float = 0
    avg_price: float = 0

    bid_price_1: float = 0
    bid_price_2: float = 0
    bid_price_3: float = 0
    bid_price_4: float = 0
    bid_price_5: float = 0

    ask_price_1: float = 0
    ask_price_2: float = 0
    ask_price_3: float = 0
    ask_price_4: float = 0
    ask_price_5: float = 0

    bid_volume_1: int = 0
    bid_volume_2: int = 0
    bid_volume_3: int = 0
    bid_volume_4: int = 0
    bid_volume_5: int = 0

    ask_volume_1: int = 0
    ask_volume_2: int = 0
    ask_volume_3: int = 0
    ask_volume_4: int = 0
    ask_volume_5: int = 0


class StraConfEntity(Entity):
    """策略配置"""
    id: str = ''
    stra_class: str = ''
    stra_file: str = ''
    symbol: str = ''
    interval_type = 0
    intervals = 0
    start_datetime = ''
    variables = {}
    params = {}
    other_data = []


class BarEntity(Entity):
    """策略用K线"""
    '''InstrumentID'''
    symbol: str = ''
    '''开盘价'''
    O: float = 0
    '''最高价'''
    H: float = 0
    '''最低价'''
    L: float = 0
    '''收盘价'''
    C: float = 0
    '''日期时间'''
    D: str = ''
    '''成交量'''
    V: int = 0


class ParmaEntity(Entity):
    """参数定义"""
    _id: str
    name: str
    min: int
    max: int
    step: int
    default: int
    multiplier: int = 1
    description: str = ''


class StraSignalEntity(Entity):
    """策略信号"""

    def __init__(self):
        '''策略实例代码'''
        self.id: str = 'stra_instance_id'
        '''策略用标的'''
        self.symbol: str = 'instrument'
        '''信号发生时间'''
        self.datetime: str = 'datetime'
        '''信号开、平、多、空标志：1＝＝开多，－1＝＝平多，－2＝＝开空，2＝＝平空，4＝＝平空开多，－4＝＝平多开空'''
        self.ocls: int = 0
        self.price: float = 0.
        self.vol: int = 1
        '''可开仓手数的百分比'''
        self.position_rate: float = 0
        '''开仓时可能涉及到的止损价'''
        self.stop_price: float = 0.
        '''信号发生时的变量值，主要是相关指标'''
        self.variables: dict = {}
        '''策略用的参数'''
        self.params: dict = {}


StrategySignal = StraSignalEntity


class StopOrderEntity(Entity):

    def __init__(self):
        self.symbol: str
        self.direction: str = 'Direction'
        self.offset: str = 'Offset'
        self.ls = 1  # long=1,short =-1
        self.price: float = 0.
        self.volume: int = 0
        self.stop_orderid: str = ''
        self.stra_name: str = ''
        self.lock: bool = False
        self.status: str = 'StopOrderStatus.WAITING'
